package com.neu.smty.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.neu.common.annotation.Log;
import com.neu.common.core.controller.BaseController;
import com.neu.common.core.domain.AjaxResult;
import com.neu.common.enums.BusinessType;
import com.neu.smty.domain.Scheduling;
import com.neu.smty.service.ISchedulingService;
import com.neu.common.utils.poi.ExcelUtil;
import com.neu.common.core.page.TableDataInfo;

/**
 * 排班管理Controller
 *
 * @author liningning
 * @date 2025-09-30
 */
@RestController
@RequestMapping("/smty/scheduling")
public class SchedulingController extends BaseController
{
    @Autowired
    private ISchedulingService schedulingService;

    /**
     * 查询排班管理列表
     */
    @PreAuthorize("@ss.hasPermi('smty:scheduling:list')")
    @GetMapping("/list")
    public TableDataInfo list(Scheduling scheduling)
    {
        startPage();
        List<Scheduling> list = schedulingService.selectSchedulingList(scheduling);
        return getDataTable(list);
    }

    /**
     * 导出排班管理列表
     */
    @PreAuthorize("@ss.hasPermi('smty:scheduling:export')")
    @Log(title = "排班管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Scheduling scheduling)
    {
        List<Scheduling> list = schedulingService.selectSchedulingList(scheduling);
        ExcelUtil<Scheduling> util = new ExcelUtil<Scheduling>(Scheduling.class);
        return util.exportExcel(list, "scheduling");
    }

    /**
     * 获取排班管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('smty:scheduling:query')")
    @GetMapping(value = "/{schedulingId}")
    public AjaxResult getInfo(@PathVariable("schedulingId") Long schedulingId)
    {
        return AjaxResult.success(schedulingService.selectSchedulingById(schedulingId));
    }

    /**
     * 新增排班管理
     */
    @PreAuthorize("@ss.hasPermi('smty:scheduling:add')")
    @Log(title = "排班管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Scheduling scheduling)
    {
        return toAjax(schedulingService.insertScheduling(scheduling));
    }

    /**
     * 修改排班管理
     */
    @PreAuthorize("@ss.hasPermi('smty:scheduling:edit')")
    @Log(title = "排班管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Scheduling scheduling)
    {
        return toAjax(schedulingService.updateScheduling(scheduling));
    }

    /**
     * 删除排班管理
     */
    @PreAuthorize("@ss.hasPermi('smty:scheduling:remove')")
    @Log(title = "排班管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{schedulingIds}")
    public AjaxResult remove(@PathVariable Long[] schedulingIds)
    {
        return toAjax(schedulingService.deleteSchedulingByIds(schedulingIds));
    }
}
